<template>
  <div class="container">
    <div class="title">
      <h2>菜单管理</h2>
      <h5>主要用于系统的菜单和按钮权限进行管理</h5>
    </div>
    <!-- 表格 -->
    <el-card class="tableCard">
      <el-button
        style="float: right; padding: 10px 20px; margin-right: 80px"
        type="primary"
        size="small"
        class="addMenu"
      >新增项目</el-button>
      <el-table :data="tableData" row-key="id">
        <el-table-column prop="title" label="名称" />
        <el-table-column prop="path" label="路由地址" />
        <el-table-column prop="icon" label="图标">
          <template #default="{ row }">
            <svg-icon :icon-class="row.icon" />
          </template>
        </el-table-column>
        <el-table-column prop="name" label="标识" />
        <el-table-column label="类型" prop="type">
          <template #default="{ row }">
            <el-tag v-if="row.type === 'menu'" type="success">{{ handleType(row.type) }}</el-tag>
            <el-tag v-else type="warning">{{ handleType(row.type) }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="权重" prop="weight" />
        <el-table-column label="状态" prop="status">
          <template #default="{ row }">
            <el-switch
              v-if="row.status === 1"
              v-model="row.status"
              active-text="显示"
              inactive-text="隐藏"
              :active-value="1"
              :inactive-value="0"
            />
            <el-switch
              v-else
              v-model="row.status"
              active-text="显示"
              inactive-text="隐藏"
              :active-value="1"
              :inactive-value="0"
            />
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作">
          <template>
            <el-button type="text" size="small">添加子级</el-button>
            <el-button type="text" size="small">删除</el-button>
            <el-button type="text" size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { getAuthManuApi } from '@/api/auth/menu'
import { tellListToTreeData } from '@/utils/index'
export default {
  name: 'ActivePage',
  data() {
    return {
      tableData: []
    }
  },
  created() {
    this.initData()
  },
  methods: {
    // 权限列表初始化
    async initData() {
      const { data: res } = await getAuthManuApi()
      this.tableData = tellListToTreeData(res, 0)
    },
    // 处理数据
    handleType(type) {
      if (type === 'menu') {
        return '菜单'
      }
      if (type === 'file') {
        return '按钮'
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  ::v-deep .el-switch__label * {
    line-height: 1;
    font-size: 12px;
    display: inline-block;
}
  padding: 0 40px;
  .addMenu {
    margin-bottom: 15px;
    margin-right: 0 !important;
  }
  .title {
    display: flex;
    align-items: center;
    h2 {
      margin-right: 20px;
    }
    h5 {
      font-weight: 400;
      color: #9c9c9d;
      vertical-align: middle;
    }
  }
  .demo-form-inline {
    display: flex;
  }
  .el-form-item {
    margin-right: 22px;

    ::v-deep .el-input__inner {
      height: 35px;
      line-height: 35px;
      width: 200px;
    }
  }

  .btn {
    padding-top: 40px;
    ::v-deep .el-form-item__content {
      display: flex;
    }
  }
  .box-card {
    margin-bottom: 10px;
  }
}
</style>

